/*
 * Copyright 2017  lvmeng9021@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.gmail.lvmeng9021.millisecondclock;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import java.sql.Time;
import java.sql.Timestamp;
import java.util.Date;

import static java.security.AccessController.getContext;

public class MillisecondClockActivity extends AppCompatActivity {
    private final static String TAG = "MillisecondClock";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_millisecond_clock);
    }


    public void timeStartClick(View view) {
        TextView displayView = (TextView) findViewById(R.id.display_clock_txt);
        DisplayTimeStampTask displayTimeStampTask = new DisplayTimeStampTask(displayView);
        displayTimeStampTask.execute();
        view.setEnabled(false);
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    private class DisplayTimeStampTask extends AsyncTask<String, String, String> {
        private TextView mDisplayView;

        public DisplayTimeStampTask(TextView texView) {
            mDisplayView = texView;
        }

        @Override
        protected String doInBackground(String... params) {
            Log.d(TAG, "doInBackground: FormatTimestamp -- " + FormatTimestamp.getInstance().toString());

            while (true) {

                publishProgress(FormatTimestamp.getInstance().toString());
            }
        }


        @Override
        protected void onProgressUpdate(String... values) {
            super.onProgressUpdate(values);
            mDisplayView.setText(values[0]);
        }
    }
}
